package com.client.smartauction;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpSocket {

	private DatagramSocket mUdpSocket;
	private DatagramPacket mUdpPacket;
	private byte[] buffer;

	private int mServerPort;

	public UdpSocket(int _serverport) {
		mServerPort = _serverport;
		try {
			mUdpSocket = new DatagramSocket(mServerPort);
			buffer = new byte[1024];
			mUdpPacket = new DatagramPacket(buffer, buffer.length);
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String Receive()
	{
		String result="";
		try {
			mUdpSocket.receive(mUdpPacket);
			result = new String(mUdpPacket.getData());
			buffer = new byte[1024];
			mUdpPacket = new DatagramPacket(buffer, buffer.length);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	
	

}
